<!DOCTYPE html>
<html>
    <head>
        <title>fastboot.js demo</title>
        <script src="../libs/zip.min.js"></script>
        <script src="../common.js" type="module"></script>
        <script src="../factory.js" type="module"></script>
        <script src="../sparse.js" type="module"></script>
        <script src="../fastboot.js" type="module"></script>
        <script src="ui.js" type="module"></script>
    </head>

    <body>
        <div>
            <p>Status: <span class="status-field">Not connected</span></p>
            <button class="connect-button">Connect device</button>
        </div>

        <hr/>

        <div>
            <form class="command-form">
                <label for="command">Command:</label>
                <input type="text" name="command" class="command-input">
                <input type="submit" value="Send">
            </form>
            <p>Result:</p>
            <pre class="result-field"></pre>
        </div>

        <hr/>

        <div>
            <form class="flash-form">
                <label for="flash-file">Flash:</label>
                <input type="file" name="flash-file" class="flash-file">
                <br>
                <label for="flash-partition">Partition:</label>
                <input type="text" name="flash-partition" class="flash-partition">
                <input type="submit" value="Flash">
            </form>
        </div>

        <hr/>

        <div>
            <p>Status: <span class="factory-status-field"></span></p>
            <button class="download-zip-button">Download factory zip</button>
            <br>
            <button class="flash-zip-button">Flash from zip</button>
            <br>
            <pre class="factory-flash-log"></pre>
        </div>

        <script>
            zip.configure({
                workerScriptsPath: "../libs/",
            });

            import("./ui.js").then(ui => {
                document.querySelector(".command-form").addEventListener("submit", ui.sendFormCommand);
                document.querySelector(".connect-button").addEventListener("click", ui.connectDevice);
                document.querySelector(".flash-form").addEventListener("submit", ui.flashFormFile);
                document.querySelector(".download-zip-button").addEventListener("click", ui.downloadZip);
                document.querySelector(".flash-zip-button").addEventListener("click", ui.flashZip);
            });
        </script>
    </body>
</html>
